<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${student.id == null ? '添加新学生' : '编辑学生信息'} + ' - 企业培训平台'">学生信息 - 企业培训平台</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        /* Form container styles */
        .form-container {
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            max-width: 600px;
            margin: 30px auto; /* Center the form */
        }

        .form-container h1 {
            text-align: center;
            color: #333;
            margin-bottom: 25px;
            font-size: 1.8em;
        }

        /* Form group for labels and inputs */
        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #555;
        }

        .form-group input[type="text"],
        .form-group input[type="password"],
        .form-group input[type="number"],
        .form-group input[type="email"],
        .form-group textarea,
        .form-group select {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1em;
            box-sizing: border-box; /* Include padding in width */
        }

        .form-group input[type="file"] {
            padding: 5px 0;
        }

        /* Form actions (buttons) */
        .form-actions {
            display: flex;
            justify-content: flex-end; /* Align buttons to the right */
            gap: 15px; /* Space between buttons */
            margin-top: 30px;
        }

        .form-actions .btn {
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1.05em;
            transition: background-color 0.2s ease-in-out;
        }

        .btn-primary {
            background-color: #007bff;
            color: white;
            border: none;
        }

        .btn-primary:hover {
            background-color: #0056b3;
        }

        .btn-secondary {
            background-color: #6c757d;
            color: white;
            border: none;
        }

        .btn-secondary:hover {
            background-color: #545b62;
        }

        /* Message styles (success/error) */
        .message {
            padding: 10px;
            margin-bottom: 15px;
            border-radius: 5px;
            text-align: center;
        }

        .success-message {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .error-message {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        /* Layout for sidebar and main content */
        body {
            display: flex;
            min-height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
            background-color: #f4f7f6;
        }

        .main-content {
            flex-grow: 1;
            padding: 20px;
            margin-left: 250px; /* Adjust if sidebar width changes */
        }
    </style>
</head>
<body>
<div th:replace="~{fragments/header :: header}"></div>

<div class="main-content">
    <div class="form-container">
        <h1 th:text="${student.id == null ? '添加新学生' : '编辑学生信息'}">添加新学生</h1>

        <div th:if="${successMessage}" class="message success-message">
            <p th:text="${successMessage}"></p>
        </div>
        <div th:if="${errorMessage}" class="message error-message">
            <p th:text="${errorMessage}"></p>
        </div>

        <form th:action="${student.id == null ? '/student/create' : '/student/edit'}" th:object="${student}" method="post">
            <input type="hidden" th:field="*{id}" th:if="${student.id != null}">
            <input type="hidden" th:field="*{userId}" th:if="${student.userId != null}">

            <div class="form-group">
                <label for="stuName">学生姓名:</label>
                <input type="text" id="stuName" th:field="*{stuName}" required>
            </div>

            <div class="form-group">
                <label for="stuNum">学号:</label>
                <input type="text" id="stuNum" th:field="*{stuNum}" required>
            </div>

            <div class="form-group">
                <label for="username">关联用户名:</label>
                <input type="text" id="username" name="username" th:value="${username}" required>
            </div>

            <div class="form-group">
                <label for="password">关联用户密码 (留空则不修改):</label>
                <input type="password" id="password" name="password" value="">
            </div>

            <div class="form-actions">
                <button type="button" class="btn btn-secondary" onclick="window.history.back()">取消</button>
                <button type="submit" class="btn btn-primary">保存</button>
            </div>
        </form>
    </div>
</div>

</body>
</html>